package com.example.demo.proxy;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.Proxy;

public class DynamicMain {
    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();

        HouseSubject proxy = (HouseSubject)Proxy.newProxyInstance(target.getClass().getClassLoader(),
                new Class[]{HouseSubject.class}, new JDKInvocationHandler(target));

        proxy.rent();

        HouseSubject proxy2 = (HouseSubject) Enhancer.create(HouseSubject.class, new CGLibMethodInterceptor(target));
        proxy2.rent();
    }
}
